package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    /**
     * 创建床位
     *
     * @param bed
     */
    @Override
    public void createBed(BedDto bed) {
        //dto转po
        Bed bed1 = BeanUtil.toBean(bed, Bed.class);
        bed1.setCreateTime(LocalDateTime.now());
        bed1.setUpdateTime(LocalDateTime.now());
        bed1.setBedStatus(0);
        bed1.setCreateBy(1L);
        bed1.setUpdateBy(1L);
        //调用mapper
        bedMapper.insertBed(bed1);
    }

    /**
     * 根据id查询床位
     * @param id
     * @return
     */
    @Override
    public BedVo getById(Integer id) {
       Bed bed =  bedMapper.selectById(id);
        BedVo bedVo = BeanUtil.toBean(bed, BedVo.class);
        return bedVo;
    }

    /**
     * 更新床位
     * @param bed
     */
    @Override
    public void updateById(BedDto bed) {
        Bed bed1 = BeanUtil.toBean(bed, Bed.class);
        bed1.setUpdateBy(1L);
        bed1.setBedStatus(0);
        bed1.setUpdateTime(LocalDateTime.now());
        bedMapper.updateById(bed1);
    }

    /**
     * 删除床位
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        bedMapper.deleteById(id);
    }

}

